package at.fhhgb.mc.android.mfb_hgb.activity;

import java.util.List;

import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import at.fhhgb.mc.android.mfb_hgb.R;
import at.fhhgb.mc.android.mfb_hgb.model.Offer;

public class FragmentSearchResult extends Fragment implements OnItemClickListener {
	List<Offer> offers;

	public void setOffers(List<Offer> offers) {
		this.offers = offers;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_overview_list, null);

		ListView lv = (ListView) view.findViewById(R.id.details_list);
		lv.setAdapter(new FragmentOverviewAdapter(getActivity(), R.layout.fragment_overview_listitem, offers));
		lv.setOnItemClickListener(this);

		return view;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Bundle b = new Bundle();
		b.putString("name", offers.get(position).getName());

		RequestDialogFragment r = new RequestDialogFragment();
		r.setArguments(b);
		r.show(getFragmentManager(), "request");
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		setHasOptionsMenu(true);
	}

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		super.onCreateOptionsMenu(menu, inflater);

		// inflater.inflate(R.menu.overview, menu);

		ActionBar actionBar = getActivity().getActionBar();

		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
		actionBar.setDisplayShowTitleEnabled(true);
		actionBar.setTitle(getString(R.string.title_searchresult));
	}
}
